import { reqBanner } from "../../request/api";
//初始值
const initState={
    banner: [],
}

//actionTypes
const types={
    CHANGE_BANNER: "HOME_CHANGE_BANNER",
}

//reducer 修改数据
const reducer=(state=initState,action)=>{
    switch(action.type){
        case types.CHANGE_BANNER:
            return {
                ...state,
                banner: action.arr
            }
        default:
            return state;
    }
}

//actionCreators组件派发的动作
export const actions={
    changeBanner: (arr) => ({type: types.CHANGE_BANNER,arr}),

    reqBanner: () => (dispatch, getState) => {
        reqBanner().then(res => {
            if (res.data.code === 200) {
                dispatch(actions.changeBanner(res.data.list))
            }
        })
    },
}

//selectors导出数据
export const getBanner = (state) => state.home.banner

export default reducer;
